<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | fastadmin: https://www.fastadmin.net/
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 前台配置接口
// +----------------------------------------------------------------------
namespace app\api\controller;

use app\common\controller\Api;
use app\common\library\Sms as Smslib;
use app\common\model\PageConfigModel;
use app\common\model\KuaiShouModel;
use think\facade\Hook;
use think\facade\Validate;
use think\Request;


class PageConfig extends Api
{
    /**
     * @param Request $request
     * @return void
     */
    public function index(Request $request)
    {
        //获取配置
        $configs = PageConfigModel::select();
        $data = [];

        if (!empty($configs)) {
            foreach ($configs as $config) {
                if ($config[PageConfigModel::NAME] === 'order_img') {
                    $config[PageConfigModel::VALUE] = '//' . $_SERVER['HTTP_HOST'] . $config[PageConfigModel::VALUE];
                }
                if ($config[PageConfigModel::NAME] === 'order_tag') {
                    $config[PageConfigModel::VALUE] = explode('|', $config[PageConfigModel::VALUE]);
                }
                if ($config[PageConfigModel::NAME] === 'kefu_url') {
                    $config[PageConfigModel::VALUE] = htmlspecialchars_decode($config[PageConfigModel::VALUE]);
                }

                $data[$config[PageConfigModel::NAME]] = $config[PageConfigModel::VALUE];
            }
        }
        $this->success('ok', ['config' => $data]);
    }
}
